#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
using namespace std;
//int main()
//{
//	string str("Hello Bit.");
//	str.reserve(111);
//	str.resize(5);
//	str.reserve(50);
//	cout << str.size() << ":" << str.capacity() << endl;
//	return 0;
//}

//class Solution {
//public:
//    void reverS(string& s, int begin, int end)
//    {
//        while (begin < end)
//        {
//            char c = s[begin];
//            s[begin] = s[end];
//            s[end] = c;
//            begin++;
//            end--;
//        }
//    }
//
//    string reverseWords(string s) {
//        int length = s.size(), begin = 0, end = 0;
//        while (end < length)
//        {
//            while (s[end] != ' '&&end<length)
//            {
//                end++;
//            }
//            reverS(s, begin, end - 1);
//            begin = end + 1;
//            end++;
//        }
//        return s;
//    }
//};
//
//int main()
//{
//    Solution str;
//    cout << str.reverseWords("Let's take LeetCode contest") << endl;
//    return 0;
//}

class Solution {
public:
    string addStrings(string num1, string num2) {
        string str;
        int end1 = num1.size() - 1;
        int end2 = num2.size() - 1;
        int next = 0;
        
        while (end1 >= 0 || end2 >= 0)
        {
            int val1 = end1 >= 0 ? num1[end1--] - '0' : 0;
            int val2 = end2 >= 0 ? num2[end2--] - '0' : 0;
            int ret = val1 + val2+next;
            next = ret / 10;
            ret = ret % 10;
            str.push_back(ret+ '0');
        }
        if (next)
        {
            str.push_back('1');
        }
        reverse(str.begin(), str.end());
        return str;
    }

    string multiply(string num1, string num2) {
        if (num1 == "0" || num2 == "0")
        {
            return "0";
        }
        string str;
        for (int end1 = num1.size() - 1; end1 >= 0; end1--)
        {
            int next = 0;
            string str1;
            for (int end2 = num2.size() - 1; end2 >= 0; end2--)
            {
                int val1 = end1 >= 0 ? num1[end1] - '0' : 0;
                int val2 = end2 >= 0 ? num2[end2] - '0' : 0;
                int ret = (val1 * val2) + next;
                next = ret / 10;
                ret = ret % 10;
                str1.insert(0, 1, ret + '0');
            }
            if (next)
            {
                str1.insert(0, 1, next + '0');
            }
            int n = num1.size() - 1 - end1;
            while (n--)
            {
                str1.push_back('0');
            }
            str = addStrings(str1, str);
        }
        return str;
    }
};

int main()
{
    Solution s;
    cout<< s.multiply("15", "23")<<endl;
    return 0;
}